library SelectAMCommand initializer init requires LegacySystem, PlayerSelectsHeroCommand, LegacyHumanAbilities

	private function Trig_Player_Selects_Assaultman_Conditions takes nothing returns boolean
		if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'H00O' ) ) then
			return false
		endif
		return true
	endfunction


	private function Trig_Player_Selects_Assaultman_Actions takes nothing returns nothing

		local unit u = GetTriggerUnit()
		local player p = GetOwningPlayer(u)
		local integer id = GetConvertedPlayerId(p)
	   
		call putUnit(p,"hero", u)

		call setPlayerDataInteger(p,"pistol_ammo",8)
		call setPlayerDataInteger(p,"pistol_type",1)
		call setPlayerDataBoolean(p,"pistol_reload",false)

		call SetUnitUserData(u,50)
		
		set udg_HeroAvailable[11] = udg_HeroAvailable[11] - 1
		set udg_PlayerIcon[id] = "ReplaceableTextures\\CommandButtons\\BTN_Unit_Assaultman.blp"
		
		call UnitAddItemById(u,'I00F') //chains 
		call UnitAddItemById(u,'I00U') //Det cords
		
		set udg_KillFactor[id] = 1.5
		
		set udg_ReloadTime[id] = 3.0
		call AddPrimaryAmmo(u, 15, 50)
		call RegisterAmmoAutoReloadListener(u)
		call RegisterAmmoEmptyListener(u)

		call InitHero(u)
		
		if GetI("player mos", id) == 4 then
			call ModifyHeroSkillPoints( u, bj_MODIFYMETHOD_ADD, 1 )
		endif
		
		//call TriggerRegisterUnitEvent(gg_trg_Demolition_skills,u,EVENT_UNIT_HERO_SKILL)
		
		

		set u = null
		set p = null
		
		if( udg_HeroAvailable[11] <= 0 ) then
			call DisableTrigger(GetTriggeringTrigger())
		endif

	endfunction


	//===========================================================================
	private function init takes nothing returns nothing
		local trigger t
		set t = CreateTrigger(  )
		call TriggerRegisterEnterRectSimple( t, GetPlayableMapRect() )
		call TriggerAddCondition( t, Condition( function Trig_Player_Selects_Assaultman_Conditions ) )
		call TriggerAddAction( t, function Trig_Player_Selects_Assaultman_Actions )
	endfunction

endlibrary